Git筆記 - in practice


觀念

  1. git stash
    可以將尚未commit的改動用 git stash git stash pop 讀取
    如此一來這些沒commit的改動就不會在切換branch時影響到其他branch

練習

git stash

當我們在master commit
master.txt:
first line , committed on master

接下來建立branch other 並且切過去創檔案 other.txt但沒有commit
other.txt:
first line , forgot to commit on other

這時切回去master查看狀態,會看到不想要的結果

這時我們切回other commit other.txt但是修改master.txt內容
master.txt:
over wrote by other
沒有commit 切回master ,這時候查看會友不想到看到的狀況

現在回到other將master.txt並沒有commit:
first line , committed on master
add second line by other
使用git stash 這些尚未commit的改變會stash進去一個box中

在master/other中都看不到尚未commit的change --> 已經在stash box

接下來master.txt commit:
first line , committed on master
second line , committed on master

切到other, 此時other的master.txt仍為:
first line , committed on master
--> 我們用git stash pop把stash box的更動改回來
master.txt:
first line , committed on master
add second line by other








你可能感興趣的文章

AI輔導室|爆裂風格文字

AI輔導室|爆裂風格文字

Vue.js 學習旅程Mile 3 – Vue 實例 與 MVVM 篇

Vue.js 學習旅程Mile 3 – Vue 實例 與 MVVM 篇

[JS101] JavaScript - 常用的內建函式

[JS101] JavaScript - 常用的內建函式






留言討論